 /**
 * The Settings Stack stores the paths and path tokens for external data.
 */
package viz.model.prefs.proxies
{
	import org.puremvc.as3.multicore.patterns.proxy.Proxy;
	
	import viz.model.prefs.vos.EdgePropVo;
	

	
	public class PreferenceProxy extends Proxy
	{

		public static const NAME:String = "PreferenceProxy";
		public static const VIZ_MODULE_URL:String = "vismoduleURL";
		
		
		
		private var properties:Array;
		private var map:Array;

		public function PreferenceProxy( ):void{
			super( NAME );
		}
		
		override public function setData( data:Object ):void{
			super.setData( checkData( data ) );
			properties = [];
		}
		
		private function checkData( data:Object ):Object{
			if(!data is XML)throw new Error ("XML expected")
			return data;
		}
		
		public function getProperty( id:String ):Object{
			if( properties[id] )return properties[id];
			properties[id] = parseProperties(id);
			return properties[id];
		}
		
		
		// todo:implement this;
		private function  parseProperties( id:String ):Object{
			var node:XML = cache.child(id)[0],
				type:String = node.@type
			switch(type){
				case "String":
					return node.toString();
				case "EdgePropVO":
					return new EdgePropVo( node );
				
				default:
					throw new Error("id or type unknown" );
					return null;
			}
		}
		
		private function get cache():XML{
			return XML(data); 
		}
		
		
		
		
		

	}
}